<?php
/**
 * Author: Hancock
 * Email: 84622365@qq.com
 * Date: 7/18/2016
 * Des: 系统管理员
 */
defined('INHkMvc') or exit('Access Invalid!');

class App_rights_member_orderModel extends AppModel
{
    public function countSums($fields, $member_id,$start_time,$end_time)
    {
        $where=[];
        $where['member_id']=$member_id;
        $where['status']=1;
        $where[]=['order_status'=>['<>',0]];
        $where[]=['cutoff_time'=>['>=',$start_time]]; 
        $where[]=['cutoff_time'=>['<',$end_time]]; 
        $data=$this->field($fields)->select($where);
        $money=0;
        if(!empty($data)){
            foreach ($data as $k => $v) {
                $money+=$v[$fields];
            }
        }
        return $money;
    }
    public function getRightsOrderByMemberIdByTime($member_id,$start_time,$end_time,$rights_status=''){
        $where=[];
        $where['status']=1;
        $where['member_id']=$member_id;
        $where[]=['cutoff_time'=>['>=',$start_time]];
        $where[]=['cutoff_time'=>['<',$end_time]];
        if(is_numeric($rights_status)){
            $where['rights_status']=$rights_status;
        }
        return $this->field('id,title,rights_money good_price,rights_tb_est_income est_income,rights_status order_status,rights_order_status status,rights_add_time,rights_cutoff_time,cutoff_time add_time')->order('cutoff_time desc')->select($where);
    }
}
